/** @jsxImportSource @emotion/react */
import * as React from "react";
import {OriginalViewProps, } from "../../common/base";
import {EntranceSetup, config设备概况,} from "./orcBase";
import {createItem, } from "../../common/eHelper";
import {useRecordList} from "../../hook/useRecordList";
import {setupItemAreaRoute} from "./orcIspConfig";
import {EditStorageContext} from "../../StorageContext";
import {Text, useTheme} from "customize-easy-ui-component";
import {ItemInstrumentTable} from "../../common/Instrument";
import {FrontCover, ItemConclusion, WitnessCraTwo} from "../../mobilecr/editorIN";
import {GenCode} from "../../common/GenCode";
import {ActionMapItem} from "../../common/ActionMapItem";
import {config编辑} from "./FormatOriginal";
import {RecheckEditor} from "../../common/editor";
import {DeviceSurveyD} from "../../crane/editor";
import {MonitoringSmms} from "./MonitoringSmms";

const defFrameM={
    'CmnTowerCrane': `{ "mg":2, "dcl":"B","cl":"A",
      "sk":[{"no":"12.10.1","r":0,"bs":[7,9],"ss":[7,9],"ts":[0,1]},0,{"no":"12.10.3","r":2,"ts":[0,1]},0,{"no":"12.10.5","r":2,"ts":[0,1]},0,0
     ]}`,
};
export const default见证=[{no:'JKXT',ti:'安全监控管理系统施工过程自检记录'}];
export const tail设备= <Text css={{"@media print": {fontSize: '0.75rem'}}}>
    注：本表设备概况是指安装安全监控管理系统的起重机的概况。若本监控系统未出独立合格证，监控系统的生产单位名称、型号、编号可填“/”。
</Text>;

const recordPrintList =[
    createItem('Entrance', <EntranceSetup/>),
    createItem('FrontCover', <FrontCover/>),
    createItem('Instrument', <ItemInstrumentTable label={'一、主要检验仪器设备性能检查'} />),
    createItem('Survey', <DeviceSurveyD config={config设备概况} children={tail设备} label={'二、设备概况'}/>),
    createItem('Item', null),
    createItem('Conclusion', <ItemConclusion  label={'四、结论(下结论)'} nxtstyp={'检验'}/>),
    createItem('Witness', <WitnessCraTwo label={'五、技术资料和工作见证材料 六、备注'} titles={['五','六','七、其它备注']} config={default见证}>
        注：本备注栏的内容在检验报告附件的备注栏内体现。
    </WitnessCraTwo>),
    createItem('Monitoring', <MonitoringSmms label={'八、观测数据及测量结果记录'}/>),

    createItem('ReCheck', <RecheckEditor  label={'附录1 检验不合格项目内容'} setup={setupItemAreaRoute}/>),
];
if(process.env.REACT_APP_TEST==='true')  recordPrintList.splice(0,0,createItem('GenCode', <GenCode type='CmnTowerCrane'
                                             frameMod={defFrameM}/>));

export const OriginalView=
  React.forwardRef((
    { action,  verId, repId='', rep,}
    :OriginalViewProps, ref
  ) => {
    const context =React.useContext(EditStorageContext);
    if(context == null)    throw new Error("EditStorageContext没有提供");
    const {storage, } =context;
    const theme = useTheme();
    const witnessNos =React.useMemo(() => {
      return storage.见证表?.map((a:any, i:number) => a && a.no);
    }, [storage.见证表]);
    const recordPrintListNow =React.useMemo(() => {
        config编辑[2].l=witnessNos;     //动态的 工作见证 列表注入：
      let routeAreas=[] as any[];
      const impressionismAs =setupItemAreaRoute({rep, orc:storage, theme});
      let extendTags =Reflect.ownKeys(impressionismAs) as string[];
      const oldItCount=recordPrintList.length;
      let prevpos=0;
      for(let p=0; p<oldItCount; p++){
        if(extendTags.indexOf(recordPrintList[p].itemArea)>=0){     //需要展开 扩充的标签
            routeAreas=routeAreas.concat(recordPrintList.slice(prevpos,p));
            const itemConfigs= impressionismAs?.[recordPrintList[p].itemArea];
            let seq = 0;
            let moreItems = [] as any;
            itemConfigs.forEach((area, x) => {
              seq += 1;
              const rowHead =<ActionMapItem key={seq} alone={false} editAreasConf={itemConfigs}
                                                    index={x} sureD editIts={config编辑} />;
              moreItems.push(createItem(area.tag, rowHead));
            });
            routeAreas=routeAreas.concat(moreItems);
            prevpos=p+1;
        }
      }
      routeAreas=routeAreas.concat(recordPrintList.slice(prevpos));
      return routeAreas;
    }, [witnessNos, verId, repId,rep, storage?._Oitems, theme]);

    const {list}=useRecordList(ref,rep,recordPrintListNow,action,verId);
    return <React.Fragment>
      {list}
        {/*      <Button  intent="primary"
                   onPress={(e) => { handleSubmit!();
                   }}
          >送打印转换器
          </Button>*/}
    </React.Fragment>;
  } );
